package org.llw.ldailytask.ui;

import java.util.ArrayList;
import java.util.Random;

import org.llw.ldailytask.R;
import org.llw.ldailytask.util.SlideAdapter;

import android.app.ListFragment;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;

public class TaskListFragment extends ListFragment {
	private SlideAdapter mAdapter;
	private ArrayList<String> mTestData;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.fragment_list, container, false);
		mTestData = new ArrayList<String>();
		randomCreateTestData();
		//mAdapter = new SlideAdapter(getActivity(), mTestData);
		setListAdapter(mAdapter);
		return v;
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		// super.onListItemClick(l, v, position, id);
		String s = (String) l.getAdapter().getItem(position);
		if (!TextUtils.isEmpty(s)) {
			Toast.makeText(getActivity(), "OnItemClick:" + s,
					Toast.LENGTH_SHORT).show();
		}
	}
	
	
	Random random = new Random();
	private void randomCreateTestData() {
		mTestData.clear();
		int length = random.nextInt(100);
		for (int i = 0; i < length; i++) {
			mTestData.add(getRandomString());
		}
	}

	private String getRandomString() {
		int length = random.nextInt(20);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < length; i++) {
			sb.append((char) (random.nextInt(26) + 97));
		}
		return sb.toString();
	}

}
